package com.wechat.file.controller;

import com.wechat.common.web.result.Result;
import com.wechat.file.request.CheckFileRequest;
import com.wechat.file.request.UploadRequest;
import com.wechat.file.response.CheckFileResponse;
import com.wechat.file.response.UploadResponse;
import com.wechat.file.service.UploadService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
@Tag(name = "文件上传", description = "文件上传")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    @Operation(summary = "文件上传检查", description = "文件上传检查（妙传、断点检查）")
    @PostMapping("/check")
    public Result<CheckFileResponse> check(@Validated @RequestBody CheckFileRequest request) {
        CheckFileResponse response = uploadService.check(request);
        return Result.success(response);
    }

    @Operation(summary = "小文件上传", description = "小文件上传")
    @PostMapping
    public Result<UploadResponse> upload(@Validated @RequestBody UploadRequest request, @RequestParam("file") MultipartFile file) {
        UploadResponse response = uploadService.upload(request, file);
        return Result.success(response);
    }


}
